package cn.gdpu.course.web.controller.admin;

import cn.gdpu.course.constant.Constant;
import cn.gdpu.course.dao.CourseStudentDao;
import cn.gdpu.course.dao.domain.CourseStudent;
import cn.gdpu.course.web.bean.PageBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2018/3/17.
 */

@Controller
@RequestMapping("/admin/chooseInfo")
public class AdmChooseInfoController {

	@Resource
	private CourseStudentDao courseStudentDao;

	@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
	public String index(HttpServletRequest request, ModelMap model) {
		String username = (String) request.getSession().getAttribute(Constant.user_name);
		model.addAttribute("username", username);
		return "admin/choose-info";
	}


	/**
	 * 返回所有选课信息
	 * @param model
	 * @param courseStudent
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
	public PageBean<CourseStudent> list(ModelMap model, CourseStudent courseStudent) {
		List<CourseStudent> courseStudents = courseStudentDao.find(courseStudent);
		PageBean<CourseStudent> data = new PageBean<CourseStudent>();
		data.setData(courseStudents);
		return data;
	}

}
